<?php

/*
	Class: DealersViewDealersCategories

	About: Author
		Rich Joslin

	About: License
		<http://communit.as/docs/license>

	About: See Also
		- <Cts_Db_Table_Abstract>
*/
class DealersViewDealersCategories extends Cts_Db_Table_Abstract {

	/* Group: Instance Variables */

	/*
		Variable: $_name
	*/
	protected $_name = 'dealers_vw_dealers_categories';

	/*
		Variable: $_primary
	*/
	protected $_primary = array('dealer_id', 'dealer_category_id');

	/* Group: Instance Methods */

	/*
		Function: getByDealerId
			Retrieves an array of records joining dealers with categories.

		Arguments:
			dealer_id - The ID of the dealer for which to retrieve joins to category IDs.

		Returns: array of join data or empty array
	*/
	function getByDealerId($dealer_id) {
		$tmp_joins = $this->fetchAll($this->select()->where('dealer_id = ?', $dealer_id));
		if (!is_null($tmp_joins)) {
			return $tmp_joins->toArray();
		} else {
			return array();
		}
	}

	/*
		Function: getCatIdsByDealerId
			Retrieves an array of category IDs which are associated to a given dealer.

		Arguments:
			dealer_id - The ID of the dealer for which to retrieve category IDs.

		Returns: array of category IDs
	*/
	function getCatIdsByDealerId($dealer_id) {
		$tmp_joins = $this->fetchAll($this->select()->where('dealer_id = ?', $dealer_id));
		if (!is_null($tmp_joins)) {
			$cat_ids = array();
			foreach ($tmp_joins as $join) {
				$cat_ids[] = $join->dealer_category_id;
			}
			return $cat_ids;
		} else {
			return array();
		}
	}

	/*
		Function: getByCatId
			Retrieves an array of records joining dealers with categories.

		Arguments:
			cat_id - The ID of the category for which to retrieve joins to dealer IDs.

		Returns: array of join data or empty array
	*/
	function getByCatId($cat_id) {
		$tmp_joins = $this->fetchAll($this->select()->where('dealer_category_id = ?', $cat_id));
		if (!is_null($tmp_joins)) {
			return $tmp_joins->toArray();
		} else {
			return array();
		}
	}

}
